<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	/*if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}*/
	if(!empty($_RQ['mobile'])){
		$params['applyno']=$_RQ['applyno'];
		$return['params']['applyno']=$_RQ['applyno'];
	}
	//$fields=array('id','partnerlevel','partnertime','createtime','partnerstatus');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_merch_bill',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	foreach($return['list'] as &$v){
		$v['merchname']=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$v['merchid']),'merchname');
		
		$v['applytime']=date('Y/m/d H:i:s',$v['applytime']);
		$v['checktime']=date('Y/m/d H:i:s',$v['checktime']);
		
	}
	$return['status']=array('0'=>'待审核','1'=>'已审核','已拒绝');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'提现管理'),			
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'applyno','title'=>'提现单号','type'=>'string'),
			array('name'=>'merchname','title'=>'商户名称','type'=>'string'),								
			array('name'=>'	price','title'=>'申请金额','type'=>'string'),
			array('name'=>'payrateprice','title'=>'抽成后金额','type'=>'string'),
			array('name'=>'	finalprice','title'=>'最终打款','type'=>'string'),				
			array('name'=>'	applytime','title'=>'申请时间','type'=>'string'),
			array('name'=>'checktime','title'=>'通过申请金额','type'=>'string'),		
		),
	/*	'action'=>array(
			array('op'=>'check','title'=>'审核','type'=>'modal'),
			
			),*/
		),
		'search'=>array(
			
			array('name'=>'applyno','width'=>15,'title'=>'提现单号','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='check'){
	$id=intval($_RQ['id']);
	$return['status']=array('0'=>'待审核','1'=>'已审核','拒绝');
	$return['item']=pdo_get('jy_weishop_member',array('id'=>$id));
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edit'=>array(
			array('name'=>'realname','title'=>'姓名','type'=>'string','read'=>true),
			array('name'=>'mobile','title'=>'电话','type'=>'string','read'=>true),
			array('name'=>'partnerstatus','title'=>'状态','type'=>'radio','options'=>'status'),
			)
			);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$post=get_postdata();
	pdo_update('jy_weishop_member',array('partnertime'=>time(),'partnerstatus'=>$post['partnerstatus']),array('id'=>$post['id']));
	exi('审核成功','','list');
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_update('jy_weishop_member',array('ispartner'=>0,'partnerstatus'=>0),array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_update('jy_weishop_member',array('ispartner'=>0,'partnerstatus'=>0),array('id'=>$id));	
			}
		}
	}
	exi('删除成功！');
}
?>